home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / BST_SystemDocs.lha / BeastV1 / Examples / B52_System / big_example.b52 next >
Encoding:
Text File  |  1996-04-04  |  2.5 KB  |  153 lines

  1. ( A B52 Program:  By FNC Slothouber )
  2.  
  3. : TD  "depth=" .STR DEPTH . CR ;
  4.  
  5. TD
  6.  
  7. "StackBot:" .STR STACKBOT . CR
  8.  
  9. CR CR
  10.       "   ----------------------------------------------------"
  11. DUP .STR CR
  12.       "   *--* A EXAMPLE B52 PROGRAM  (C)  FNC Slothouber *--*"
  13. .STR CR .STR CR CR
  14.  
  15.  
  16.            ( --------------------
  17.              Some String Examples
  18.              -------------------- )
  19.  
  20.  
  21. ( Strings can be 127 characters long. )
  22.  
  23. "This Is A test String"   (This Put the address of the string on stack)
  24.  
  25. DUP . CR   (Print Address )
  26.  
  27. .STR CR    (Print The String)
  28.  
  29. : str> .STR CR ;   (Handy function)
  30.  
  31.  
  32. ( Example of nested conditional statements )
  33.  
  34. 1 IF
  35.   {
  36.     1 IF "This Should Appear" str> THEN
  37.   }
  38.   ELSE
  39.   {
  40.     "This Should not Appear" str>
  41.   }
  42.   THEN
  43.  
  44. ( Notice that you can use  { and } where ever you like
  45.   the compiler just ignores them, but you can use them
  46.   to add some structure to the program -- This is an
  47.   example of a comment btw )
  48.  
  49. } { { {{{{  }}}}} {}}}}}}}}} {{  (See the compiler does not complain)
  50.  
  51.  
  52. ( Some examples with constants )
  53.  
  54. 19671111 CONSTANT a_big_number
  55.  
  56. ( This defines the constant a_big_number, and we can now use it )
  57.  
  58. "Value of a_big_number : " .STR a_big_number . CR
  59.  
  60. "Value of a_big_number times 33 : " .STR a_big_number 33 * . CR
  61.  
  62.  
  63.  
  64. ( An Example of using TAGS )
  65.  
  66. : PRT_TAG DUP DUP @ . SPACE 4 + @ . CR ;  (Print Tag info)
  67. : NXT_TAG 8 + ;                           (Advance to the next Tag)
  68.  
  69. (INP_TAGS = the tag list that was passed to us by the calling
  70.  program )
  71.  
  72.  
  73. INP_TAGS
  74.  
  75. PRT_TAG  NXT_TAG
  76. PRT_TAG  NXT_TAG
  77. PRT_TAG  DROP
  78.  
  79. TD
  80.  
  81. (Example of a Callback   CB2 = callback function with 2 parameters)
  82.  
  83. 1 2 CALLB CB2
  84.  
  85. 2 0 DO I I I * CALLB CB2 LOOP
  86.  
  87. TD
  88.  
  89. ( an exmaple of  FIND and EXECUTE )
  90.  
  91. -20 9 FIND + EXECUTE . CR
  92.  
  93. ( This does the same as )
  94.  
  95. -20 9 + . CR
  96.  
  97. TD
  98.  
  99. (Lets look how many space we used in the dictionary)
  100.  
  101. ENTRY . CR
  102.  
  103. "StackBot:" .STR STACKBOT . CR
  104.  
  105. ( Return a value to the Calling program )
  106. ( Can also be used to return the address of a newly created taglist)
  107.  
  108. TD
  109. 2 1  . .
  110. 2 1 SWAP   . .
  111.  
  112.  
  113.  
  114. ( BEAST STUFF   BEAST STUFF   BEAST STUFF )
  115.  
  116.  
  117. "myclass" 10 BST_MakeClass
  118. DUP CR "Class=" .STR . CR
  119.  
  120. CONSTANT My_Class
  121.  
  122.  
  123. My_Class
  124.  
  125. :METHOD Init  CR CR "Hallo" .STR CR
  126.          "METHOD CALL" .STR CR CR
  127.      "TagList=" .STR . CR
  128.      "Object=" .STR . CR
  129.  DUP "Flags=" .STR . CR
  130. RETURN ;
  131.  
  132. #OBM_INIT CLSS_AddMethod
  133.  
  134. My_Class BST_AddClass DROP
  135.  
  136. 0 "myclass" 0 OBJ_NewObject
  137. CONSTANT My_Object
  138.  
  139. My_Object "Object=" .STR . CR
  140.  
  141. My_Object #OBM_INIT 0 0  OBJ_DoMethod DROP
  142.  
  143. My_Object OBJ_DisposeObject DROP
  144.  
  145. My_Class BST_RemoveClass DROP
  146.  
  147. My_Class BST_FreeClass DROP
  148.  
  149.  
  150. 0 RETURN
  151.  
  152.  
  153.